#ifndef MENU_ITEM_CPP_INCLUDED
#define MENU_ITEM_CPP_INCLUDED
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include "Menu_Item.h"

//#include "Description.h"

using namespace std;

Menu_item::Menu_item()
{
    Menu_item::menu_item_id = 0;
	Menu_item::cat_id = "";
	Menu_item::recipe_id = 0;
	Menu_item::menu_item_name = "";
	Menu_item::price = 0;
	Menu_item::descr.descr = "";
}

Menu_item::Menu_item(int id, string cat, int rec, string n, double amt, Description s)
{
	Menu_item::menu_item_id = id;
	Menu_item::cat_id = cat;
	Menu_item::recipe_id = rec;
	Menu_item::menu_item_name = n;
	Menu_item::price = amt;
	Menu_item::descr = s; //all this makes the menu item variables that are public private
}

void Menu_item::copy(Menu_item& item)
{
    Menu_item::menu_item_id = item.get_menu_item_id();
	Menu_item::cat_id = item.get_cat_id();
	Menu_item::recipe_id = item.get_recipe_id();
	Menu_item::menu_item_name = item.get_menu_item_name();
	Menu_item::price = item.get_price();
	Menu_item::descr = item.get_descr();
}

void Menu_item::display()
{
    if (menu_item_id == -1)//tje menu_item_id variable is hijacked to be -1 if the stuff being scanned is only 2 variable instead of 6 variable. This decides to show 2 or 6 variables then
    {
        cout << "\nCategory ID:\t" << cat_id;
        cout << "\nMenu Item name:\t" << menu_item_name;
    }

	else
        {
        cout << "\n\nMenu Item ID:\t" << menu_item_id;
        cout << "\nCategory ID:\t" << cat_id;
        cout << "\nRecipe ID:\t"<<recipe_id;
        cout << "\nMenu Item name:\t" << menu_item_name;
        cout << "\nPrice:\t" << price;
        cout << "\nDescription:\t" << descr.descr;
        }
}

int const Menu_item::get_menu_item_id()
{
    return Menu_item::menu_item_id;
}

string const Menu_item::get_cat_id()
{
    return Menu_item::cat_id;
}

int const Menu_item::get_recipe_id()
{
    return Menu_item::recipe_id;
}

string const Menu_item::get_menu_item_name()
{
    return Menu_item::menu_item_name;
}

double const Menu_item::get_price()
{
    return Menu_item::price;
}

Description const Menu_item::get_descr()
{
    return Menu_item::descr;
}

string const Menu_item::get_descr_string()
{
    return Menu_item::descr.descr;
}

void read_menu_items(vector<Menu_item>& menu_item_list, vector<Category>& Category_list, string filepath)
{
	ifstream inFile;  //this whole thing reads the catmenu.dat
	inFile.open("catmenu.dat");
	if(inFile.fail())
	{
		cerr << "\n\nERROR: Unable to open file catmenu.dat\n\n";
	}

	int end;
	inFile >> end; //grabs the amount of lines to check
	//cout << end;

	for(int x = 0;x < end;x++) //grabs the first chunk of data
	{
	    string next = "";
	    string stuff = "";
		int id = -1;
		int rec = -1;
		string cat, n;
		double amt = -1;
		Description s;
		id = -1;

		int catID; //temporary variable to put the parsed text -- Archie
		string catName;
		inFile >> catID >> catName; //puts data into cat and n Change to catid and catname --Archie
		//Menu_item(id, cat, rec, n, amt, s).display(); //for debugging --archie
		Category_list.push_back(Category(catID,catName)); //pushes stuff into the menu_item vector --change to the category --Archie
	}
    inFile >> end; //checks the amount of lines to check in the second batch of data
	//cout << end;

	for(int x = 0;x < end;x++) //this does the same thing as the previous, except scans for and write sinto the 6 different variables
	{
	    bool flag = 0;
	    string next = "";
	    string stuff = "";
		int id, rec;
		string cat, n;//, string n, double amt, Description s;
		double amt;
		Description s;
		inFile >> id >> cat >> rec >> n >> amt;
		do{ //because the description is a set of strings connected by spaces with '#' being a stop, this builds a string, stops when it reaches '#', and exports the string into the decsription
		    s.descr += next;
		    s.descr += " ";
		    inFile >> next;
		    if(string(next) == "#"){flag = 1;} //once it reaches '#', this breaks the loop
		}
		while (flag == 0);
		//Menu_item(id, cat, rec, n, amt, s).display(); //for debugging --archie
		menu_item_list.push_back(Menu_item(id, cat, rec, n, amt, s));

	}

}
#endif // MENU_ITEM_CPP_INCLUDED
